package com.dhcc.sds.base.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.node.ZTreeNode;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.sds.base.entity.SdsQceitemDicEntity;
import com.dhcc.sds.base.entity.SdsQcfitemDicEntity;
import com.dhcc.sds.base.entity.SdsQcformItemEntity;
import com.dhcc.sds.base.service.ISdsQceitemDicService;
import com.dhcc.sds.base.service.ISdsQcfitemDicService;
import com.dhcc.sds.base.service.ISdsQcformItemService;
import com.dhcc.sds.base.service.ISdsSecondaryHeaderService;
import com.dhcc.sds.standard.entity.SdsStandRisitemMatchEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 单病种指标统计取值配置
 *
 * @ClassName: SdsIndFieldConfigController
 * @Description: TODO
 * @author zhangdc
 * @date 2021-08-27 10:09:53
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdsindfieldconfig")
public class SdsIndFieldConfigController extends BaseController {

    private String PREFIX = "/backend/sds/sdsindfieldconfig/";

    @Autowired
    private ISdsSecondaryHeaderService sdsSecondaryHeaderService;

    /**
     * 跳转到单病种指标统计取值配置列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdsindfieldconfig.html";
    }

    /**
     * 二级表头和病种项目或值域关联
     */
    @RequestMapping(value = "/compare")
    @ResponseBody
    public Object compare(@RequestParam Long fieldId, @RequestParam Long formItemId, @RequestParam Long formDicId) {
        this.sdsSecondaryHeaderService.compare(fieldId, formItemId, formDicId);
        return R.ok();
    }

    /**
     * 撤销二级表头和病种项目或值域关联
     */
    @RequestMapping(value = "/undo")
    @ResponseBody
    public Object undo(@RequestParam Long fieldId, @RequestParam Long formItemId, @RequestParam Long formDicId) {
        this.sdsSecondaryHeaderService.undo(fieldId, formItemId, formDicId);
        return R.ok();
    }

    /**
     * 获取二级表头的tree列表
     */
    @RequestMapping(value = "/tree")
    @ResponseBody
    public List<ZTreeNode> fieldTree() {
        return sdsSecondaryHeaderService.getFieldTree();
    }

    /**
     * 获取病种项目数据
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/listFormItem")
    @ResponseBody
    public Object listFormItem(@RequestParam Map<String, Object> params) {
        Page<SdsQcformItemEntity> page = new PageFactory<SdsQcformItemEntity>().defaultPage();
        //List<SdsQcformItemEntity> result = this.sdsQcformItemService.page(page,params);
        List<SdsQcformItemEntity> result = this.sdsSecondaryHeaderService.pageFormItem(page,params);
        page.setRecords((List<SdsQcformItemEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }


    /**
     * 获取病种值域数据
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/listFormDic")
    @ResponseBody
    public Object listFormDic(@RequestParam Map<String, Object> params) {
        Page<SdsQcfitemDicEntity> page = new PageFactory<SdsQcfitemDicEntity>().defaultPage();
        //List<SdsQcfitemDicEntity> result = this.sdsQcfitemDicService.page(page,params);
        List<SdsQcfitemDicEntity> result = this.sdsSecondaryHeaderService.pageFormDic(page,params);
        page.setRecords((List<SdsQcfitemDicEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }
}
